import httplib
import sys
reload(sys)
sys.setdefaultencoding('utf-8') 

def httpRequest(method,url,para={}):
    print method
    try:
        _urld = httplib.urlsplit(url)
        conn = httplib.HTTPConnection(_urld.netloc,80,True,5)
        conn.connect()
        para = rulib.urlencode(para)
        if method == 'get':
            conn.putrequest("GET",url,None)
            conn.putheader("Content-Length",'0')
        elif method == 'post':
            conn.putrequest("POST",url)
            conn.putheader("Content-Length",str(len(pata)))
        conn.putheader("Connection","close")
        conn.endheaders()

        if len(para):
            conn.send(data)

        response = conn.getresponse()
        httpbody = response.read().encode('gbk')
        response.close()
        conn.close()
    except:
        httpbody = ''
    return httpbody


def login():
    #self.qq = raw_input('QQ:')
    #self.pwd = raw_input('password:')
    qq = 296770220
    pwd = 315941518
    print qq
    loginresponse = httpRequest('post','http://pt.3g.qq.com/handleLogin',{'r':'324525157','qq':qq,'pwd':pwd,'toQQchat':'true','q_from':'','modifySKey':0,'loginType':1})
    print type(loginresponse)
    
    

    


if __name__ == "__main__":
    print 112
    login()
